// mine.js

// 自定义标签
var app = getApp();
var iconPath = "../../images/icons/"
var tabs = [
    {
        "icon": iconPath + "mark.png",
        "iconActive": iconPath + "markHL.png",
        "title": "点击查看",
        "extraStyle": "",
    },
    
    
]
var userInfo = {
    avatar: "https://pic4.zhimg.com/e515adf3b_xl.jpg",

}


Page({

    // data
    data: {
    
        listData:[
            {"code":"01","text":"text1","type":"type1"},
            {"code":"02","text":"text2","type":"type2"},
            {"code":"03","text":"text3","type":"type3"},
            {"code":"04","text":"text4","type":"type4"},
            {"code":"05","text":"text5","type":"type5"},
            {"code":"06","text":"text6","type":"type6"},
            {"code":"07","text":"text7","type":"type7"}
          ]
          ,
        name:'',
        sex:'',
        IDcard:'',
        fileID:'',
        houseID:'',
        ioNumber:'',
        fileUrl:'',


        // 展示的tab标签
        tabs: tabs,

        // 当前选中的标签
        currentTab: "tab1",

        // 高亮的标签索引
        highLightIndex: "0",

        // 模态对话框样式 
        modalShowStyle: "",

        // 待新建的日记标题
        diaryTitle: "",

        // TODO 用户信息
        userInfo: userInfo,
    },

    xgxx(){
        wx.navigateTo({
          url: '../xg/xg',
        })

    },
    // 隐藏模态框
    hideModal() {
        this.setData({modalShowStyle: ""});
    },

    // 清除日记标题
    clearTitle() {
        this.setData({diaryTitle: ""});
    },

    onLoad:function(options){
            var mima=app.globalData.mima;
            console.log(abc);
            console.log(mima);
            this.setDate({
                mima:app.globalData.mima
            }
            )
          },
        onLaunch: function () {
            var that = this;
            that.globalData.mima = mima;
            this.setDate({
                mima:app.globalData.mima
            }
            )
          },
    onShow() {
        var mima=app.globalData.mima;
        this.setDate({
            mima:app.globalData.mima
        }
        )
        },

        getExcel: function (contentArr) {
            let that = this;
            var name=app.globalData.name;
        var sex=app.globalData.sex;
        var IDcard=app.globalData.IDcard;
        var houseID=app.globalData.houseID;
        var ioNumber=app.globalData.ioNumber;
        console.log(name)
            wx.cloud.callFunction({
              name: 'excelexport',
              data: {
                excelhead: ["姓名", "性别", "身份证号", "住户房号", "出入次数"],
                excelbody: [{'name':name,'sex':sex,'IDcard':IDcard,'houseID':houseID,'ioNumber':ioNumber}]
            
            
              },
              success: function (res) {
                console.log(res.result.fileID);
                console.log(456);
                wx.cloud.getTempFileURL({
                    fileList: [res.result.fileID],
                    success: res => {
                      // get temp file URL
                      console.log("文件下载链接", res.fileList[0].tempFileURL)
                      that.setData({
                        fileUrl: res.fileList[0].tempFileURL,
                        
                      })
                    },
                    fail: err => {
                      // handle error
                    }
                  })

              },
              fail: function (res) {
                console.log(res);
                console.log(123);
              }
            })
          },
        
    // 点击tab项事件
    touchTab: function(event){
        var mima=app.globalData.mima;
        console.log(mima);
        var name=app.globalData.name;
        var sex=app.globalData.sex;
        var IDcard=app.globalData.IDcard;
        var fileID=app.globalData.fileID;
        var houseID=app.globalData.houseID;
        var ioNumber=app.globalData.ioNumber;
        console.log(name);
        var tabIndex = parseInt(event.currentTarget.id);
        var template = "tab" + (tabIndex + 1).toString();

        this.setData({
            currentTab: template,
            highLightIndex: tabIndex.toString(),
            mima:app.globalData.mima,
            name:app.globalData.name,
            IDcard:app.globalData.IDcard,
            fileID:app.globalData.fileID,
            sex:app.globalData.sex,
            houseID:app.globalData.houseID,
            ioNumber:app.globalData.ioNumber,
        }
        );
    },

    // 点击新建日记按钮
    touchAdd: function (event) {
        this.setData({
            modalShowStyle: "opacity:1;pointer-events:auto;"
        })
    },

    // 新建日记
    touchAddNew: function(event) {
        this.hideModal();

        wx.navigateTo({
            url: "../new/new?title=" + this.data.diaryTitle,
        });
    },

    // 取消标题输入
    touchCancel: function(event) {
        this.hideModal();
        this.clearTitle();
    }, 

    // 标题输入事件
    titleInput: function(event) {
        this.setData({
            diaryTitle: event.detail.value,
        })
    }
})
